package jvm.error;

import java.lang.reflect.Method;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

/**
 * @author jiangwz
 * @create 2019/9/17.
 */
public class MetaSpaceOOMDemo {

    static class OOMTest{}

    /**
     * -XX:MetaspaceSize=8m -XX:MaxMetaspaceSize=8m
     * @param args
     */
    public static void main(String[] args){
      int i = 0;
      try {
          while (true) {
              i++;
              Enhancer enhancer = new Enhancer();
              enhancer.setSuperclass(OOMTest.class);
              enhancer.setUseCache(false);
              enhancer.setCallback(new MethodInterceptor() {
                  @Override
                  public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                      return methodProxy.invokeSuper(o, args);
                  }
              });
              Object o = enhancer.create();
              System.out.println(o);
          }
      }catch(Exception e){
          e.printStackTrace();
      }

    }
}
